document.addEventListener('plusready',function(){
	showWating();
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=article&a=holes",
		success :function(data){
			plus.storage.setItem('newhole',data);
			var newdata = $.parseJSON(data);
			var htm='';
			$.each(newdata, function(k1,v1) {
				if(v1.hole){
					$.each(v1.hole, function(k,v) {
						plus.nativeUI.closeWaiting();
//						console.log(JSON.stringify(v));
						htm = '<li class="mui-table-view-cell mui-media mui-col-xs-4" data-id="'+v.id+'"><div class="mui-media-body ">' + v.title + '</div></li>';
						$('.xue:contains('+v1.classname+')').parent().find('ul').append(htm);
						/*arr.push({'classname':v.classname,'title':v.title});*/
					});
				}
			});
			$('.mui-col-xs-4').on('tap',function(){
				console.log($(this).attr('data-id'));
				goNewPage('jk-point.html', {aid:$(this).attr('data-id')});
			})
		},
		error :function(e){
			var getdata = plus.storage.getItem('newhole');
			var newdata = $.parseJSON(getdata);
			var htm='';
			$.each(newdata, function(k1,v1) {
				if(v1.hole){
					$.each(v1.hole, function(k,v) {
//						console.log(JSON.stringify(v));
						htm = '<li class="mui-table-view-cell mui-media mui-col-xs-4" data-id="'+v.id+'"><div class="mui-media-body ">' + v.title + '</div></li>';
						$('.xue:contains('+v1.classname+')').parent().find('ul').append(htm);
						/*arr.push({'classname':v.classname,'title':v.title});*/
					});
				}
			});
			$('.mui-col-xs-4').on('tap',function(){
				console.log($(this).attr('data-id'));
				goNewPage('jk-point.html', {aid:$(this).attr('data-id')});
			})
		}
	});
	//获取分类
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=article&a=holeType",
		success :function(data){
			plus.storage.setItem('holeType',data);
			var nedata = $.parseJSON(data);
			//五输穴
			var fivepoint = nedata.fivepoint.split(',');
			var htm1 = '<li class="mui-table-view-cell coms" data-id=00><a href="#top-1">全部</a></li>';
			$.each(fivepoint, function(ke, vo) {
				plus.nativeUI.closeWaiting();
				come = vo.split('=');
				if(come[1] != 0){
					htm1 += '<li class="mui-table-view-cell coms" data-id="'+ come[1] +'"><a href="#top-1">'+come[0]+'</a></li>';
				}
			});
			$('.wushuxue').html(htm1);
			$(".coms").on('tap',function(){
				showWating();
				$(".mui-col-xs-6:eq(0) span:eq(0)").text($(this).text());
				$(".mui-col-xs-6:eq(1) span:eq(0)").text('其他');
				$(".mui-col-xs-6:eq(0) span:eq(0)").attr('data-id',$(this).attr('data-id'));
				console.log($(this).attr('data-id'));
				searchM($(this).attr('data-id'),'fivepoint');
			});	
			//其他
			var otherhole = nedata.otherhole.split(',');
			var htm2 = '<li class="mui-table-view-cell other" data-id=00><a href="#top-2">全部</a></li>';
			$.each(otherhole, function(k, v) {
				plus.nativeUI.closeWaiting();
				hole = v.split('=');
				if(hole[1] != 0){
					htm2 += '<li class="mui-table-view-cell other" data-id="'+ hole[1] +'"><a href="#top-2">'+hole[0]+'</a></li>';
				}
			});
			$('.qita').html(htm2);
			$(".other").on('tap',function(){
				showWating();
				$(".mui-col-xs-6:eq(0) span:eq(0)").text('五输穴');
				$(".mui-col-xs-6:eq(1) span:eq(0)").text($(this).text());
				$(".mui-col-xs-6:eq(1) span:eq(0)").attr('data-id',$(this).attr('data-id'));
				console.log($(this).attr('data-id'));
				searchM($(this).attr('data-id'),'otherhole');
			});	
		},
		error :function(e){
			var dat = plus.storage.getItem('holeType');
			var nedata = $.parseJSON(dat);
			//五输穴
			var fivepoint = nedata.fivepoint.split(',');
			var htm1 = '<li class="mui-table-view-cell coms" data-id=00><a href="#top-1">全部</a></li>';
			$.each(fivepoint, function(ke, vo) {
				plus.nativeUI.closeWaiting();
				come = vo.split('=');
				htm1 += '<li class="mui-table-view-cell coms" data-id="'+ come[1] +'"><a href="#top-1">'+come[0]+'</a></li>';
			});
			$('.wushuxue').html(htm1);
			$(".coms").on('tap',function(){
				showWating();
				$(".mui-col-xs-6:eq(0) span:eq(0)").text($(this).text());
				$(".mui-col-xs-6:eq(1) span:eq(0)").text('其他');
				$(".mui-col-xs-6:eq(0) span:eq(0)").attr('data-id',$(this).attr('data-id'));
				console.log($(this).attr('data-id'));
				searchM($(this).attr('data-id'),'fivepoint');
			});	
			//其他
			var otherhole = nedata.otherhole.split(',');
			var htm2 = '<li class="mui-table-view-cell other" data-id=00><a href="#top-2">全部</a></li>';
			$.each(otherhole, function(k, v) {
				plus.nativeUI.closeWaiting();
				hole = v.split('=');
				htm2 += '<li class="mui-table-view-cell other" data-id="'+ hole[1] +'"><a href="#top-2">'+hole[0]+'</a></li>';
			});
			$('.qita').html(htm2);
			$(".other").on('tap',function(){
				showWating();
				$(".mui-col-xs-6:eq(0) span:eq(0)").text('五输穴');
				$(".mui-col-xs-6:eq(1) span:eq(0)").text($(this).text());
				$(".mui-col-xs-6:eq(1) span:eq(0)").attr('data-id',$(this).attr('data-id'));
				console.log($(this).attr('data-id'));
				searchM($(this).attr('data-id'),'otherhole');
			});	
		}
	});
},false)
//搜索的结果——>a:选中的值，b:属于哪个选框
function searchM(a,b){
	console.log(apiRoot+"?m=home&c=Article&a=selectX&field="+a+"&type="+b);
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=Article&a=selectX&field="+a+"&type="+b,
		dataType :'json',
		success :function(data){
			$('.mui-col-xs-4').hide();
			if(data.length > 0){
				plus.nativeUI.closeWaiting();
				var list = '';
				$.each(data, function(k1,v1) {
					console.log(JSON.stringify(v1));
					$('li div:contains('+v1.title+')').parent().show();
				});
			}else{
				plus.nativeUI.closeWaiting();
				$('.medicine').html('');
				toast('无相关穴位');
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
	
}